package lunsfordhall.androidapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class quadraticformula extends Activity{

	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.quadraticformula);
        
        
        final EditText edittext2 = (EditText) findViewById(R.id.edittext2);
        final EditText edittext = (EditText) findViewById(R.id.edittext);
        final EditText edittext3 = (EditText) findViewById(R.id.edittext3);
        
        final Button button = (Button) findViewById(R.id.button1);
        
        button.setOnClickListener(new OnClickListener() {
        	public void onClick(View v) {
        		 TextView xpos = (TextView)findViewById(R.id.textview);
        		 TextView xneg = (TextView)findViewById(R.id.textview2);
        		 double answer = 0;
        		 double answer2 = 0;
              	
              	double b = Double.parseDouble(edittext2.getText().toString());
              	double a = Double.parseDouble(edittext.getText().toString());
              	double c = Double.parseDouble(edittext3.getText().toString());
              	answer = quadpos(a,b,c);
              	answer2 = quadneg(a,b,c);
              //	xpos.setText("X = : "+String.valueOf(answer));
              	xneg.setText("X = : "+String.valueOf(answer2));
	}
	
});
            
	}
	
	public static double quadpos(double a, double b, double c){
		double x;
		x = ((b * -1) + (Math.sqrt(Math.pow(b, 2) - 4*a*c)/2*a));
		return x;
	}
	
	public static double quadneg(double a, double b, double c){
		double x;
		x = ((b * -1) - (Math.sqrt(Math.pow(b, 2) - 4*a*c)/2*a));
		return x;
	}
}